package com.qianji.petmall.order.web;

import com.alipay.api.AlipayApiException;
import com.qianji.petmall.order.config.AlipayTemplate;
import com.qianji.petmall.order.service.OrderService;
import com.qianji.petmall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author liang zai
 * @date 2022/5/17 17:19
 * @description
 */
@Controller
public class PayController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private AlipayTemplate alipayTemplate;

    //支付成功后需要用户跳到订单列表页
    @GetMapping(value = "payOrder",produces = "text/html")
    @ResponseBody
    public String payOrder(@RequestParam("orderSn") String orderSn) throws AlipayApiException {
        PayVo payVo = orderService.payOrder(orderSn);
        //返回的是一个html页面，交给浏览器管理就行
        String pay = alipayTemplate.pay(payVo);
        return pay;
    }
}
